package com.itfreer.bpm.calculation;

import java.text.DecimalFormat;
import java.util.Date;

import org.springframework.stereotype.Component;
@Component
public class TimeCalculation implements ITimeCalculation{

	@Override
	public Long calculateTime(Date start, Date end) {
		// TODO 计算两个时间之间的时间差
		return (end.getTime()-start.getTime());
	}

	@Override
	public String Dayformate(Long spendTime) {
		//TODO 算法需要实现
		double result=(spendTime/1000.0/60/24);
		DecimalFormat df = new DecimalFormat("#.00");
		return String.valueOf(df.format(result))+"天";
	}

	@Override
	public String DayHourformate(Long spendTime) {
		//TODO 算法需要实现
		double d_day=(spendTime/1000.0/60/60/24);
		
		Long day=(spendTime/1000/60/60/24);
		
		int hours=(int) Math.floor((d_day-day)*24);
		String result="";
		if(day>0) {
			result=day+"天";
		}
		if(hours>0) {
			result=result+hours+"小时";
		}
		return result;
	}

	@Override
	public String DayHourMintorformate(Long spendTime) {
		//TODO 算法需要实现
		double d_day=(spendTime/1000.0/60/60/24);
		
		Long day=(spendTime/1000/60/60/24);
		
		int hours=(int) Math.floor((d_day-day)*24);
		
		double d_hours=(d_day-day)*24;
		
		int min=(int) Math.floor((d_hours-hours)*60);
		String result="";
		if(day>0) {
			result=day+"天";
		}
		if(hours>0) {
			result=result+hours+"小时";
		}
		if(min>0) {
			result=result+min+"分钟";
		}
		return result;
	}

}
